# Maintainer: Oliver Smith <ollieparanoid@postmarketos.org>
# Co-Maintainer: Clayton Craft <clayton@craftyguy.net>
pkgname=postmarketos-mkinitfs
pkgver=2.6.1
pkgrel=0
pkgdesc="Tool to generate initramfs images for postmarketOS"
url="https://postmarketos.org"
depends="
	boot-deploy>=0.9
"
makedepends="go scdoc"
replaces="mkinitfs"

triggers="$pkgname.trigger=\
/lib/firmware/*:\
/usr/lib/systemd/boot:\
/usr/lib/udev:\
/usr/libexec/pmos-tests-initramfs:\
/usr/share/deviceinfo:\
/usr/share/kernel/*:\
/usr/share/mkinitfs-triggers:\
/usr/share/mkinitfs/*\
"

# mkinitfs-vendor-$pkgver.tar.gz: vendored Go deps, is part of the release:
# https://gitlab.postmarketos.org/postmarketOS/postmarketos-mkinitfs/-/releases
source="
	https://gitlab.postmarketos.org/postmarketOS/postmarketos-mkinitfs/-/archive/$pkgver/postmarketos-mkinitfs-$pkgver.tar.gz
	https://gitlab.com/api/v4/projects/postmarketOS%2Fpostmarketos-mkinitfs/packages/generic/mkinitfs-vendor-$pkgver/$pkgver/mkinitfs-vendor-$pkgver.tar.gz
	"

install="$pkgname.post-upgrade"
arch="all"
license="GPL-2.0-or-later"
provider_priority=999  # higher priority than Alpine's mkinitfs
provides="initramfs-generator"
subpackages="$pkgname-doc"

export GOCACHE="${GOCACHE:-"$srcdir/go-cache"}"
export GOMODCACHE="${GOMODCACHE:-"$srcdir/go"}"
export GOPATH="$srcdir"
export GOTMPDIR="${GOTMPDIR:-"$srcdir"}"

prepare() {
	default_prepare
	ln -s "$srcdir"/vendor "$builddir"/vendor
}

build() {
	unset LDFLAGS  # passed to Go as linker flags, which are invalid

	# For https://gitlab.com/qemu-project/qemu/-/issues/2560
	case "$CARCH" in
	x86_64)
		make VERSION="$pkgver" DISABLE_GOGC=1 ;;
	*)
		make VERSION="$pkgver" ;;
	esac
}

package() {
	make PREFIX=/usr DESTDIR="$pkgdir" install
}

check() {
	go test ./...
}

sha512sums="
53b69dcd4ad09439e9c4449947e374db714b4b5acf5847fa8fdac024e3e9803ecd9f0ea7170a696cc878cd883fda46e1e6076ea6f7936ef1166d942a1bb2ffc0  postmarketos-mkinitfs-2.6.1.tar.gz
5b96cfbfc652d744a717d19c17b446ef94f09b00152a7620112a66709057fa56f203855519ed53b948f79424715fc20b93d44aaa38051fac9ceb7eda586020b3  mkinitfs-vendor-2.6.1.tar.gz
"
